package com.fyzk.activity.lottery.basketball.fragment;

import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.PopupWindow;

import com.fyzk.activity.lottery.basketball.JL_HG_Pop;
import com.fyzk.adapter.JCLQBaseAdapter;
import com.fyzk.adapter.JCLQHGAdapter;
import com.fyzk.model.JCLQMatchData;
import com.fyzk.utils.LogUtil;
import com.fyzk.utils.LotteryIDUtils;
import com.fyzk.utils.ScreenUtils;
import com.fyzk.utils.Utils;

/**
 * 混合过关玩法
 * 
 * @author miao
 * 
 */
public class BasketballHGFragment extends BasketballWFBaseFragment implements JCLQBaseAdapter.JLPopOpenListener {

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return super.onCreateView(inflater, container, savedInstanceState);
	}

	@Override
	public void onResume() {
		super.onResume();
		if(!isDanguan){
			notifyList();
		}
	}

	@Override
	public String getTextStr() {
		return "混合过关";
	}

	@Override
	protected int getLotteryId() {
		return LotteryIDUtils.JLHH_LOTTERY_ID_INT;
	}


	public int countChangCi() {
		int changCi = 0;
		for (int i = 0; i < infos_all.size(); i++) {
			for (int j = 0; j < infos_all.get(i).matchDatas.size(); j++) {
				JCLQMatchData data = infos_all.get(i).matchDatas.get(j);
				if (data.clickNum > 0) {
					changCi++;
				}
			}
		}
		return changCi;

	}

	@Override
	public void clear() {
		for (int i = 0; i < infos_all.size(); i++) {
			if (infos_all.size() > 0) {
				for (int j = 0; j < infos_all.get(i).matchDatas.size(); j++) {
					JCLQMatchData data = infos_all.get(i).matchDatas.get(j);
					for (JCLQMatchData.SPInfo info : data.plInfos) {
						info.isSel = false;
					}
					data.clickNum = 0;
					data.setSfcNum(0);
				}
			}
		}
		adapterChange();
	}
	
	
	@Override
	protected void adapterChange() {
		if (adapter == null) {
			adapter = new JCLQHGAdapter(getActivity(), infos);
			if (adapter != null) {
				adapter.setOnJCLQTongJiListener(activity);
			}
			exListView.setAdapter(adapter);
			for (int i = 0; i < adapter.getGroupCount(); i++) {
				exListView.expandGroup(i);
			}
		} else {
			adapter.notifyDataSetChanged();
		}
		adapter.SetJLPopOpenListener(this);

	}

	@Override
	public void open(JCLQMatchData data) {
		int height = Utils.dip2px(510f);
		JL_HG_Pop bf_sel_pop = new JL_HG_Pop(getContext(), WindowManager.LayoutParams
				.MATCH_PARENT, height, data);
		LogUtil.v("y=" + (ScreenUtils.getInstance().getHeight() - bf_sel_pop.getHeight()));
		LogUtil.v("p_height=" + bf_sel_pop.getHeight());
		setBackgroundAlpha(0.5f);
		bf_sel_pop.showAtLocation(getView(), Gravity.NO_GRAVITY, 0, ScreenUtils.getInstance()
				.getHeight() -
				height);
		bf_sel_pop.setOnDismissListener(new PopupWindow.OnDismissListener() {
			@Override
			public void onDismiss() {
				setBackgroundAlpha(1.0f);
				adapterChange();
			}
		});
	}

	public void setBackgroundAlpha(float bgAlpha) {
		WindowManager.LayoutParams lp = getActivity().getWindow()
				.getAttributes();
		lp.alpha = bgAlpha;
		getActivity().getWindow().setAttributes(lp);
	}
}
